import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * 通信Socket
 */
public class MySocket {
	private Socket socket;
	private InputStream inputStream;
	private OutputStream outputStream;

	public MySocket(String ip, int port) {
		try {
			socket = new Socket(ip,port);
			inputStream = socket.getInputStream();
			outputStream = socket.getOutputStream();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	//向redis服务器端发送的指令
	public void send(String str) {
		try {
			outputStream.write(str.getBytes());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	//从redis服务器接收返回值
	public String read() {
		byte[] bytes = new byte[1024];
		int count = 0;
		try {
			count = inputStream.read(bytes);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new String(bytes,1,count);
	}
}
